import java.awt.Dimension;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.List;


/**
 * Simulates objects moving around in a bounded environment.
 * @author Robert C. Duvall revised by Difan Zhao
 */
public class Simulation {
    private List<Material> myMaterial;
    private ArrayList<Mass> myMass;
    private ArrayList<Mass> myRealMass;
    private static Canvas myContainer;

    /**
     * Create a Canvas with the given size.
     */
    public Simulation(Canvas container) {
        myMaterial = new ArrayList<Material>();

        myContainer = container;
    }
    /**
     * add all materials to a list.
     */
    public void add(Material m) {
        myMaterial.add(m);
    }

    /**
     * Paint all shapes on the canvas.
     * 
     * @param pen used to paint shape on the screen
     */
    public void paint(Graphics2D pen) {
        for (Material m : myMaterial) {
            m.paint(pen);
        }

    }

    /**
     * Called by each step of timer, multiple times per second.
     * 
     * This should update the state of the animated shapes by just
     * a little so they appear to move over time.
     */
    public void update(double dt) {
        updateMovers(dt);
    }

    void updateMovers(double dt) {

        for (Material m : myMaterial) {
            m.update(this, dt);
        }

    }
    
    public  ArrayList<Mass> getRealMass(){
        myMass=getMassList();
        for(Mass m: myMass){
            if(m.getId()>=0 &&  m.getMass()   >0){
                myRealMass.add((Mass)m);
            }
        }
        return myRealMass;
    }

    
    public ArrayList<Mass> getMassList(){
        for(Material m: myMaterial){
            if(m.getId()>=0){
                myMass.add((Mass)m);
            }
        }
        return myMass;
    }

    /**
     * Returns size (in pixels) of the game area.
     */
    public static Dimension getSize() {
        return myContainer.getSize();
    }

    public Mass getMass(int id) {
        for (Material m : myMaterial) {
            if (m.getId() == id) {
                return (Mass) m;
            }
        }
        return null;
    }
<<<<<<< HEAD
    
    public List<Mass> getMassList() {
        ArrayList<Mass> masses= new ArrayList<Mass>();
        for (Material m : myMaterial) {
            if (m.getId()>=0) {
                 masses.add((Mass) m);
            }
        }
        return masses;
    }
    
    public List<Mass> getRealMass(){
        List<Mass> masses = getMassList();
        List<Mass> realMasses = new ArrayList<Mass>();
        for(Mass m:masses){
            if(m.getMass()>0){
                realMasses.add(m);
            }
        }
        return realMasses;
    }
=======
>>>>>>> db3a22b30e69cbc14bd7f2fe6aa88415016cfe58
}
